

package com.hazelcast.jet.impl;

import java.util.HashMap;
import java.util.Map;

/**
 * Thread local holder class for Processor class loaders
 * <p>
 * This class is used to access processor class loader in deserialization code, where an object (typically metaSupplier,
 * supplier or a processor instance) needs to be deserialized with processor classloader and there is no access to
 * JobExecutionService, which manages the processor classloaders.
 * <p>
 * The ThreadLocal
 */
public final class ProcessorClassLoaderTLHolder {

    private static final ThreadLocal<Map<String, ClassLoader>> CLASS_LOADERS = ThreadLocal.withInitial(HashMap::new);

    private ProcessorClassLoaderTLHolder() {
    }

    public static ClassLoader get(String key) {
        return CLASS_LOADERS.get().get(key);
    }

    static void putAll(Map<String, ClassLoader> map) {
        CLASS_LOADERS.get().putAll(map);
    }

    static void remove() {
        CLASS_LOADERS.remove();
    }
}
